/**
 * 
 */
package co.fitstart.admin.web.controller.system;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.demo2do.core.support.Result;
import com.demo2do.core.utils.DateFormatUtils;
import com.demo2do.core.utils.JsonUtils;

import co.fitstart.admin.entity.security.Login;
import co.fitstart.admin.web.interceptor.MenuSetting;
import co.fitstart.admin.web.resolver.Secure;
import co.fitstart.admin.web.view.ExcelTemplateView;

/**
 * @author mohanlan
 *
 */
@Controller
@RequestMapping("/principal-salary")
@MenuSetting("menu-system")
public class PrincipalSalaryController {
	
	private static final Logger logger = LoggerFactory.getLogger(PrincipalSalaryController.class);
	
	/**
	 * 
	 * @param login
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "", method = RequestMethod.GET)
    @MenuSetting("submenu-principal-salary-management")
	public ModelAndView list(@Secure Login login, HttpServletRequest request) {
		
		ModelAndView modelAndView = new ModelAndView("system/principal/principal-salary-list");
		
		
		
		return modelAndView;
	}
	
	/**
	 * 
	 * @param login
	 * @return
	 */
	@RequestMapping(value = "/edit-targrt", method = RequestMethod.GET)
	public ModelAndView editTarget(@Secure Login login) {
		
		ModelAndView modelAndView = new ModelAndView("system/principal/principal-salary-target");
		
		return modelAndView;
	}
	
	/**
	 * 
	 * @param login
	 * @return
	 */
	@RequestMapping(value = "/edit-target", method = RequestMethod.PATCH)
	public @ResponseBody String onEditTarget(@Secure Login login) {
		
		Result result = new Result();
		
		try {
			
		} catch (Exception e) {
			logger.error("edit salary target error", e);
			result.fail().message("设置绩效目标失败");
		}
		
		return JsonUtils.toJsonString(result);
	}
	
	/**
	 * 
	 * @param login
	 * @return
	 */
    @RequestMapping(value = "/export-view", method = RequestMethod.GET)
    public ModelAndView export(@Secure Login login) {
        
        ModelAndView modelAndView = new ModelAndView("principal/principal-salary-report-export");
        
        modelAndView.addObject("today", DateFormatUtils.format(new Date(), "yyyy-MM-dd"));
        
        return modelAndView;
    }
    
    /**
     * 
     * @param login
     * @return
     */
    @RequestMapping(value = "/export", method = RequestMethod.GET)
    public ModelAndView onExport(@Secure Login login) {
        ModelAndView modelAndView = new ModelAndView(new ExcelTemplateView("principal-salary-report.xls"));
        
        return modelAndView;
    }

}
